package com.xuecheng.teaching.controller;

import com.xuecheng.api.teaching.WorkRecordApi;
import com.xuecheng.api.teaching.model.dto.CourseWorkRecordDTO;
import com.xuecheng.api.teaching.model.dto.WorkRecordDTO;
import com.xuecheng.api.teaching.model.vo.WorkRecordVO;
import com.xuecheng.teaching.common.util.UAASecurityUtil;
import com.xuecheng.teaching.convert.CourseWorkConvert;
import com.xuecheng.teaching.service.WorkRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 作业提交记录 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class WorkRecordController implements WorkRecordApi {

    @Autowired
    private WorkRecordService  workRecordService;

    /**
     * 根据作业id查询作业批阅详情
     * @param courseWorkId
     * @return
     */
    @Override
    @GetMapping("work-record/read-over-all/{courseWorkId}")
    public CourseWorkRecordDTO queryCourseWorkRecById(@PathVariable Long courseWorkId) {

        Long companyId = UAASecurityUtil.getCompanyId();

        return workRecordService.queryCourseWorkRecById(courseWorkId,companyId);
    }



    /**
     * 批阅作业
     * @param workRecordVO
     * @return
     */
    @Override
    @PutMapping("work-record/correction")
    public WorkRecordDTO correctionCourseWork(@RequestBody WorkRecordVO workRecordVO) {

        WorkRecordDTO workRecordDTO = CourseWorkConvert.INSTANCE.vo2dto(workRecordVO);

        return workRecordService.correctionCourseWork(workRecordDTO);
    }
}
